home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Filling Shapes with a Gradient Brush / Creating a Path Gradient / Specifying Points on the Boundary / APP2 / GDITEST82.dpr
Encoding:
Text File  |  2003-10-15  |  4.0 KB  |  131 lines

  1. program GDITEST82;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10.  
  11. // The following example constructs a path gradient brush based on an array of
  12. // points. A color is assigned to each of the five points in the array. If you
  13. // were to connect the five points by straight lines, you would get a five-sided
  14. // polygon. A color is also assigned to the center (centroid) of that polygon รน
  15. // in this example, the center (80, 75) is set to white. The final code statement
  16. // in the example fills a rectangle with the path gradient brush.
  17.  
  18. // The color used to fill the rectangle is white at (80, 75) and changes
  19. // gradually as you move away from (80, 75) toward the points in the array. For
  20. // example, as you move from (80, 75) to (0, 0), the color changes gradually
  21. // from white to red, and as you move from (80, 75) to (160, 0), the color
  22. // changes gradually from white to green.
  23.  
  24. Procedure OnPaint(DC: HDC);
  25. var
  26.   graphics : TGPGraphics;
  27.   Brush: TGPPathGradientBrush;
  28.   colors: array[0..4] of TGPColor;
  29.   count: Integer;
  30. const
  31.   ptsF: array[0..4] of TGPPointF =
  32.    ((x: 0.0  ; y: 0.0),
  33.     (x: 160.0; y: 0.0),
  34.     (x: 160.0; y: 200.0),
  35.     (x: 80.0 ; y: 150.0),
  36.     (x: 0.0  ; y: 200.0));
  37.  
  38. begin
  39.   graphics := TGPGraphics.Create(DC);
  40.  
  41.   // Construct a path gradient brush based on an array of points.
  42.   Brush:= TGPPathGradientBrush.Create(PGPPointF(@ptsF), 5);
  43.  
  44.   // An array of five points was used to construct the path gradient
  45.   // brush. Set the color of each point in that array.
  46.   colors[0] := MakeColor(255, 255, 0, 0); // (0, 0) red
  47.   colors[1] := MakeColor(255, 0, 255, 0); // (160, 0) green
  48.   colors[2] := MakeColor(255, 0, 255, 0); // (160, 200) green
  49.   colors[3] := MakeColor(255, 0, 0, 255); // (80, 150) blue
  50.   colors[4] := MakeColor(255, 255, 0, 0); // (0, 200) red
  51.  
  52.   count := 5;
  53.   Brush.SetSurroundColors(@colors, count);
  54.  
  55.   // Set the center color to white.
  56.   Brush.SetCenterColor(MakeColor(255, 255, 255, 255));
  57.  
  58.   // Use the path gradient brush to fill a rectangle.
  59.   graphics.FillRectangle(Brush, MakeRect(0, 0, 180, 220));
  60.  
  61.   Brush.Free;
  62.   graphics.Free;
  63. end;
  64.  
  65.  
  66. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  67. var
  68.   Handle: HDC;
  69.   ps: PAINTSTRUCT;
  70. begin
  71.   case message of
  72.     WM_PAINT:
  73.       begin
  74.         Handle := BeginPaint(Wnd, ps);
  75.         OnPaint(Handle);
  76.         EndPaint(Wnd, ps);
  77.         result := 0;
  78.       end;
  79.  
  80.     WM_DESTROY:
  81.       begin
  82.         PostQuitMessage(0);
  83.         result := 0;
  84.       end;
  85.  
  86.    else
  87.       result := DefWindowProc(Wnd, message, wParam, lParam);
  88.    end;
  89. end;
  90.  
  91. var
  92.   hWnd     : THandle;
  93.   Msg      : TMsg;
  94.   wndClass : TWndClass;
  95. begin
  96.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  97.    wndClass.lpfnWndProc    := @WndProc;
  98.    wndClass.cbClsExtra     := 0;
  99.    wndClass.cbWndExtra     := 0;
  100.    wndClass.hInstance      := hInstance;
  101.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  102.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  103.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  104.    wndClass.lpszMenuName   := nil;
  105.    wndClass.lpszClassName  := 'GettingStarted';
  106.  
  107.    RegisterClass(wndClass);
  108.  
  109.    hWnd := CreateWindow(
  110.       'GettingStarted',       // window class name
  111.       'Specifying Points on the Boundary',       // window caption
  112.       WS_OVERLAPPEDWINDOW,    // window style
  113.       Integer(CW_USEDEFAULT), // initial x position
  114.       Integer(CW_USEDEFAULT), // initial y position
  115.       Integer(CW_USEDEFAULT), // initial x size
  116.       Integer(CW_USEDEFAULT), // initial y size
  117.       0,                      // parent window handle
  118.       0,                      // window menu handle
  119.       hInstance,              // program instance handle
  120.       nil);                   // creation parameters
  121.  
  122.    ShowWindow(hWnd, SW_SHOW);
  123.    UpdateWindow(hWnd);
  124.  
  125.    while(GetMessage(msg, 0, 0, 0)) do
  126.    begin
  127.       TranslateMessage(msg);
  128.       DispatchMessage(msg);
  129.    end;
  130. end.
  131.